﻿// -----------------------------------------------------------------------
// <copyright file="Tire.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex03.GarageLogic
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Tire
    {
        private string m_Manufacturer;
        private float m_CurrentAirPressure;
        private float m_MaxAirPressure;

        internal Tire(string i_Manufacturer, float i_CurrentAirPressure, float i_MaxAirPressure)
        {
            m_Manufacturer = i_Manufacturer;
            m_CurrentAirPressure = i_CurrentAirPressure;
            m_MaxAirPressure = i_MaxAirPressure;
        }

        public float CurrentAirPressure
        {
            get { return m_CurrentAirPressure; }
            set { m_CurrentAirPressure = value; }
        }

        public string Manufacturer
        {
            get { return m_Manufacturer; }
            set { m_Manufacturer = value; }
        }

        internal float MaxAirPressure
        {
            get { return m_MaxAirPressure; }
            set { m_MaxAirPressure = value; }
        }

        internal void AddAirPressure(float i_AmountPressureToAdd)
        {
            if (i_AmountPressureToAdd + this.m_CurrentAirPressure > this.m_MaxAirPressure || i_AmountPressureToAdd < 0)
            {
                throw new ValueOutOfRangeException(0, m_MaxAirPressure - m_CurrentAirPressure, "Amount air pressure to fill is not between limits");
            }
            else
            {
                this.m_CurrentAirPressure += i_AmountPressureToAdd;
            }
        }

        internal void AddMaxAirPressure()
        {
            AddAirPressure(m_MaxAirPressure - m_CurrentAirPressure);
        }

        internal void GetTireData(ref StringBuilder o_VehicleData)
        {
            o_VehicleData.AppendFormat(
                "{0}Tire manufacturer: {1}{0}Current air pressure: {2} PSI{0}Max air pressure: {3} PSI{0}", Environment.NewLine, m_Manufacturer, m_CurrentAirPressure.ToString(), m_MaxAirPressure.ToString());
        }
    }
}
